package com.zyb.warehouse.mapper;

import com.zyb.warehouse.entity.ProductType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Description:分类表持久层接口
 */
@Mapper
public interface ProductTypeMapper {

    /**
     * 查询商品分类
     *
     * @return
     */
    @Select("select * from product_type")
    List<ProductType> selectAllCategory();

    /**
     * 验证商品分类编号是否重复
     *
     * @param typeCode
     * @return
     */
    @Select("select * from product_type where type_code=#{typeCode}")
    ProductType selectProductCategoryByTypeCode(String typeCode);

    /**
     * 根据分类名字查询名字是否重复
     *
     * @param typeName
     * @return
     */
    @Select("select * from product_type where type_name=#{typeName}")
    ProductType selectProductCategoryByTypeName(String typeName);

    /**
     * 添加商品分类
     *
     * @param productType
     * @return
     */
    Integer insertProductCategory(ProductType productType);

    /**
     * 删除商品分类
     *
     * @param typeId
     * @return
     */
    @Delete("delete from product_type where type_id=#{typeId} or parent_id=#{typeId}")
    Integer deleteProductCategory(Integer typeId);

    /**
     * 修改商品分类
     *
     * @param productType
     * @return
     */
    Integer updateProductCategory(ProductType productType);
}
